package com.jida.weather.job;

import com.jida.weather.service.WeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
public class ScheduledTaskJob {

//    @Autowired
//    RedisTemplate redisTemplate; //操作Redis数据库的模板类

    @Autowired
    WeatherService weatherService;

    // @Autowired
    //RestTemplate restTemplate;   //访问第三方接口的模板类

    /**
     * 每隔15分钟拉取天气数据缓存到Redis
     */
    @Scheduled(cron="0/1 * * * * ?")
    public void cacheWeatherData(){
        //1.拉取哪些城市的天气数据？
        //    101020100  101030100
        String[] cityArr={"101020100","101030100"};
        for(int i=0;i<cityArr.length;i++){
            //需要从第三方接口获取最新鲜的数据
//            WeatherResponse weatherResponse=weatherService.queryWeatherByCityId(cityArr[i]);
//            System.out.println("query result:"+weatherResponse.getResult().getArea());
//            //2.怎么缓存数据？
//            redisTemplate.opsForHash().put("weatherTable",cityArr[i],weatherResponse);
            weatherService.cacheWeatherData(cityArr[i]);


        }



    }


}